package com.spring.ioc.demo.test;

import com.spring.ioc.demo.dao.UserDaoImpl;
import com.spring.ioc.demo.domain.User;
import com.spring.ioc.demo.service.impl.UserServiceImpl;
import org.apache.commons.dbcp.BasicDataSource;
import org.junit.Test;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 使用面向过程思维和配置文件的方式去实现容器化管理Bean（请看SpringIocTest02）
 * @author zero
 * */
public class SpringIocTest01 {


    @Test
    public void Test01(){
        // A程序员他其实只想使用业务对象去调用想应的查询服务
        // 但是现在A程序员还要去进行业务对象的构建
        // A程序员其实也不了解业务对象的构造细节

        UserServiceImpl userService = new UserServiceImpl();
        UserDaoImpl userDao = new UserDaoImpl();
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://10.0.204.143:3306/test_db?characterEncoding=utf8");
        dataSource.setUsername("admin");
        dataSource.setPassword("root");
        userDao.setDataSource(dataSource);
        userService.setUserDao(userDao);

        Map<String,Object> paramMap = new HashMap<>(1);
        paramMap.put("name","张三");

        List<User> results = userService.queryUsers(paramMap);
        System.out.println(results);
    }
}
